#include <iostream>
using namespace std;

const int N = 2e5 + 10;
int n;
int a[N];
int f[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) 
    {
        cin >> a[i];
        f[i] = f[i - 1] + a[i];
    }

    int ret = -1e8;
    int prevmin = 0;
    for(int i = 1; i <= n; i++)
    {
        ret = max(ret, f[i] - prevmin);
        prevmin = min(prevmin, f[i]);
    }
    cout << ret << endl;
    return 0;
}